#include "stdafx.h" //it should be added to make sure to enable the precompiled header

#include "my_library.h"

void console_out_welcome(void)
{
	std::cout<<"***************Welcome to Tiny Memory DataBase***************"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"***            Wirte by alexandercer@gmail.com            ***"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"*************************************************************"<<std::endl;
}

void console_out_prompt(void)
{
	std::cout<<"TMDB=>";
}

std::string console_get_command(void)
{
	std::string command_line;
	//std::cin>>command_line; //will lead to a error: input -c aaa will lead to only have "-c"
	getline(std::cin,command_line);

#ifdef _DEBUG
	std::cout<<"_DEBUG:"<<command_line<<std::endl;
#endif

	return command_line;
}

void console_out_help(void)
{
	console_out_welcome();
	std::cout<<"*************The Help for Tiny Memory DataBase***************"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"***            Wirte by alexandercer@gmail.com            ***"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"              Send E-mail to me for more detial             "<<std::endl \
		<<"*************************************************************"<<std::endl;
}

void console_out_bye(void)
{
	std::cout<<"***************Welcome to Tiny Memory DataBase***************"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"***            Wirte by alexandercer@gmail.com            ***"<<std::endl \
		<<"                                                             "<<std::endl \
		<<"*************************************************************"<<std::endl;

	std::cout<<"**************************Bye!*******************************"<<std::endl;
}

bool console_command_valid(const std::string &)
{
	return true;
}

void console_out_error_command(void)
{
	std::cout<<"You are using the wrong command, Please use the normal command"<<std::endl<<"I Feel Sorry About It!"<<std::endl;
}

bool console_command_arguments_valid(const std::string & command_line_entire)
{
	std::fstream test(command_line_entire.c_str(),std::fstream::in);
	if (test.fail()) { test.close(); return false;}
	else { test.close(); return true;}
}

void console_out_error_arguments(void)
{
	std::cout<<"Your arguments is not valid, even your command line is OK."<<std::endl<<"Please make sure you are using the right or valid argumens!"<<std::endl<<"I Feel Sorry About It!"<<std::endl;
}


CMD_KIND parse_command(const std::string& command_line, std::string& command_line_end)
{
	if (command_line.length() > 3)
	{
		std::string command_line_head=command_line.substr(0,2);
		command_line_end.clear();
		command_line_end.append(command_line.substr(3));

#ifdef _DEBUG
		std::cout<<"_DEBUG:"<<command_line_head<<std::endl<<"_DEBUG:"<<command_line_end<<std::endl;
#endif

		if(command_line_head=="-c") 
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::CREAT"<<std::endl;
#endif
			return CMD_KIND::CREAT;
		}
		else if(command_line_head=="-i")
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::IMPORT"<<std::endl;
#endif
			return CMD_KIND::IMPORT;
		}
		else if(command_line_head=="-d")
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::DELETE"<<std::endl;
#endif
			return CMD_KIND::DELETE;
		}
		else if(command_line_head=="-s")
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::SELECT"<<std::endl;
#endif
			return CMD_KIND::SELECT;
		}
		else if(command_line_head=="-u")
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::UPDATA"<<std::endl;
#endif
			return CMD_KIND::UPDATA;
		}
		else
		{
#ifdef _DEBUG
			std::cout<<"_DEBUG:"<<"CMD_KIND::ERROR"<<std::endl;
#endif
			return CMD_KIND::ERROR;
		}
	}
	else
	{
#ifdef _DEBUG
		std::cout<<"_DEBUG:"<<"CMD_KIND::ERROR"<<std::endl;
#endif
		return CMD_KIND::ERROR;

	}
}




